package com.uchengwang.ui.cm_ui.rychat.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.rychat.bean.RyUserBean;
import com.uchengwang.ui.utils.UCommonUtil;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/10/22.
 * 融云群成员
 */

public class RyMemberAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<RyUserBean> list = new ArrayList<>();

    public RyMemberAdapter(Context context){
        this.context = context;
    }
    public void setData(List<RyUserBean> list){
        this.list = list;
        notifyDataSetChanged();
    }

    public List<RyUserBean> getData(){
        return list;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.ucity_apply_item, parent, false);

        return new RYMemberVH(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        RYMemberVH holder = (RYMemberVH) h;
        final RyUserBean bean = list.get(position);
        if (TextUtils.isEmpty(bean.getMemberAvatar())){
            ImageManager.getInstance().loadImage(context, holder.imageView, R.drawable.no_head, ImageManager.ImageType.CIRCLE);
        }else {
            ImageManager.getInstance().loadImage(context, holder.imageView, bean.getMemberAvatar(), ImageManager.ImageType.CIRCLE);
        }
        holder.imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UCommonUtil.getUtil().toUserActivity((Activity) context, bean.getMemberUid());
            }
        });

    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class RYMemberVH extends RecyclerView.ViewHolder{
        private ImageView imageView;

        public RYMemberVH(View itemView) {
            super(itemView);
            AutoUtils.autoSize(itemView);

            imageView = (ImageView) itemView.findViewById(R.id.ucity3_item_apply);
        }
    }
}

